 package server.quest;

 import client.MapleCharacter;
 import client.MapleQuestStatus;
 import client.inventory.Item;
 import client.inventory.MapleInventoryType;
 import client.skills.Skill;
 import client.skills.SkillFactory;
 import constants.ItemConstants;
 import java.io.Serializable;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
 import tools.Pair;

 public class MapleQuestComplete
   implements Serializable
 {
   private static final long serialVersionUID = 9179541993413738569L;
   private final MapleQuestCompleteType type;
/*  21 */   private final List<Pair<Integer, Integer>> dataStore = new ArrayList<>();









   public MapleQuestComplete(MapleQuestCompleteType type, int itemId, int num) throws SQLException {
/*  32 */     this.type = type;
/*  33 */     if (type == MapleQuestCompleteType.item) {
/*  34 */       this.dataStore.add(new Pair(Integer.valueOf(itemId), Integer.valueOf(num)));
     }
   }







   public boolean check(MapleCharacter chr) {
     int[] partyQuests;
     int sRankings;
/*  47 */     switch (this.type) {
       case job:
/*  49 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  50 */           if (((Integer)a.getRight()).intValue() == chr.getJob() || chr.isGM()) {
/*  51 */             return true;
           }
         }
/*  54 */         return false;
       case skill:
/*  56 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  57 */           boolean acquire = (((Integer)a.getRight()).intValue() > 0);
/*  58 */           int skill = ((Integer)a.getLeft()).intValue();
/*  59 */           Skill skil = SkillFactory.getSkill(skill);
/*  60 */           if (acquire) {
/*  61 */             if (chr.getSkillLevel(skil) == 0)
/*  62 */               return false;  continue;
           }
/*  64 */           if (chr.getSkillLevel(skil) > 0 || chr.getMasterLevel(skil) > 0) {
/*  65 */             return false;
           }
         }
/*  68 */         return true;
       case quest:
/*  70 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  71 */           MapleQuestStatus q = chr.getQuest(MapleQuest.getInstance(((Integer)a.getLeft()).intValue()));
/*  72 */           int state = ((Integer)a.getRight()).intValue();
/*  73 */           if (state == 0 || (
/*  74 */             q == null && state == 0)) {
             continue;
           }
/*  77 */           if (q == null || q.getStatus() != state) {
/*  78 */             return false;
           }
         }

/*  82 */         return true;
       case item:
/*  84 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  85 */           int itemId = ((Integer)a.getLeft()).intValue();
/*  86 */           short quantity = 0;
/*  87 */           MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
/*  88 */           for (Item item : chr.getInventory(iType).listById(itemId)) {
/*  89 */             quantity = (short)(quantity + item.getQuantity());
           }
/*  91 */           int count = ((Integer)a.getRight()).intValue();
/*  92 */           if (quantity < count || (count <= 0 && quantity > 0)) {
/*  93 */             return false;
           }
         }
/*  96 */         return true;
       case partyQuest_S:
/*  98 */         partyQuests = new int[] { 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1300, 1301, 1302 };
/*  99 */         sRankings = 0;
/* 100 */         for (int i : partyQuests) {
/* 101 */           String rank = chr.getOneInfo(i, "rank");
/* 102 */           if (rank != null && rank.equals("S")) {
/* 103 */             sRankings++;
           }
         }
/* 106 */         return (sRankings >= 5);
     }
/* 108 */     return true;
   }


   public boolean removeQuestItem(MapleCharacter chr) {
/* 113 */     switch (this.type) {
       case item:
/* 115 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 116 */           int itemId = ((Integer)a.getLeft()).intValue();
/* 117 */           short quantity = 0;
/* 118 */           MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
/* 119 */           for (Item item : chr.getInventory(iType).listById(itemId)) {
/* 120 */             quantity = (short)(quantity + item.getQuantity());
           }
/* 122 */           int count = ((Integer)a.getRight()).intValue();
/* 123 */           if (quantity < count || (count <= 0 && quantity > 0)) {
/* 124 */             return false;
           }
/* 126 */           chr.removeItem(itemId, count);
         }
/* 128 */         return true;
     }
/* 130 */     return true;
   }

   public MapleQuestCompleteType getType() {
/* 134 */     return this.type;
   }


   public String toString() {
/* 139 */     return this.type.toString();
   }

   public List<Pair<Integer, Integer>> getDataStore() {
/* 143 */     return this.dataStore;
   }
 }


/* Location:              C:\PGX\Server.jar!\server\quest\MapleQuestComplete.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */